from netCDF4 import Dataset
from wrf import getvar
import numpy as np
import csv
import os


# This function extracts the real track data.
#-----------------------------------------------------------------------------------------------------------------------------------------
def Extract_Track_Data (Real_Data_Dir, file_name, List, Variable_Name):
	os.chdir(Real_Data_Dir)
	with open(file_name) as f:
		reader = csv.reader(f)
		next (reader)
		row_header = next(reader)
		#print (row_header)
		for row in reader:
			List.append(float(row[row_header.index(Variable_Name)]) )
	return (List)
	
# This function extracts the real track data.
#-----------------------------------------------------------------------------------------------------------------------------------------
def Extract_Coordinates_3 (Output_File, Track_List, Variable_Name):
  with open(Output_File) as f:
    reader = csv.reader(f)
    next (reader)
    row_header = next(reader)
    #print (row_header)
    for row in reader:
      Track_List.append(float(row[row_header.index(Variable_Name)]) )
  return (Track_List) 

# This function extracts the real track data.
#-----------------------------------------------------------------------------------------------------------------------------------------
def Extract_Coordinates_2 (Dir, Forecast_Outputs, Lat_Header, Lon_Header):
	os.chdir(Dir)
	Lat_Forecast = []
	Lon_Forecast = []
	with open(Forecast_Outputs) as f:
		reader = csv.reader(f)
		next (reader)
		row_header = next(reader)
		#print (row_header)
		for row in reader:
			Lat_Forecast.append(float(row[row_header.index(Lat_Header)]))
			Lon_Forecast.append(float(row[row_header.index(Lon_Header)]))
	return (Lat_Forecast, Lon_Forecast)